package com.sambo.inspection.util;

import android.content.Context;
import android.view.WindowManager;

import com.sambo.inspection.InspectionApplication;

public class DeviceUtil {

    private static Float density = InspectionApplication.getInstance().getResources().getDisplayMetrics().density;
    private static Float scaledDensity = InspectionApplication.getInstance().getResources().getDisplayMetrics().scaledDensity;

    public static int dp2Px(float dp) {
        return (int) (dp * density + 0.5);
    }

    public static float px2Dp(int px) {
        return (float) (px / density + 0.5);
    }

    public static int px2sp(float px) {
        return (int) (px / scaledDensity + 0.5f);
    }

    public static float sp2px(float sp) {
        return sp * density + 0.5f;
    }

    public static int getDisplayWidth(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        return wm.getDefaultDisplay().getWidth();
    }

    public static int getDisplayHeight(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        return wm.getDefaultDisplay().getHeight();
    }

}
